<?php
require "setup.php";
require "top_page.php";
?>


<h1><?php echo _("Queue"); ?></h1>

<?php

function show_queue() {
	$res=queue();
	if($res["STATUS"] == "404") {
		// The queue is empty
		echo _("There is no track in the queue.");
	} else if($res["STATUS"] == "225") {
		?>
		<table class="tracks">
		<tr><th><?php echo _("User"); ?></th><th><?php echo _("Artist"); ?></th><th><?php echo _("Name"); ?></th><th><?php echo _("Rating"); ?></th><th></th></tr>
		<?php
		for($i=0; $i<$res["COUNT"]; $i++) {
			echo "<tr".($i%2 ? " class=\"pairLine\"" : "")."><td>".$res["$i"]["USER"]."</td><td>".$res["$i"]["ARTIST"]."</td><td><a href=\"albums.php?album=".$res["$i"]["ALBUM_NO"]."&amp;track=".$res["$i"]["TRACK_NO"]."\">".$res["$i"]["TITLE"]."</a></td><td>".$res["$i"]["RATING"]."</td><td><a class=\"delqueue\" href=\"queue.php?del=1&amp;album=".$res["$i"]["ALBUM_NO"]."&amp;track=".$res["$i"]["TRACK_NO"]."\">X</a></td></tr>";
		}
		?>
		</table>
		<?php
	}
}

function add_queue($album="", $track="") {
	$res=queue($album, $track);
	if($res["STATUS"] == "247") {
		// Added to the queue
		echo "<p class=\"notification\">"._("Added to the queue.")."</p>";
	} else {
		echo "<p class=\"notification\">"._("ERROR !")."</p>";
	}
}

function del_queue($album, $queue) {
	$res=unqueue($album, $queue);
	if($res["STATUS"] == "254") {
		// ok
		echo "<p class=\"notification\">"._("Deleted from the queue.")."</p>";
	} else {
		echo "<p class=\"notification\">"._("ERROR !")."</p>";
	}

}

if($_GET["add"] == "1") {
	add_queue($_GET["album"], $_GET["track"]);
} else if($_GET["del"] == "1") {
	del_queue($_GET["album"], $_GET["track"]);
} else if(isset($_POST["select"])) {
	foreach($_POST["select"] AS $add) {
		$add_t = explode(",", $add);
		add_queue($add_t[0], $add_t[1]);
	}
}

show_queue();

?>

<?php
require "bottom_page.php";
?>
